package com.hxzy.servlet.UmsMemberTag;

import com.hxzy.entity.UmsMemberTag;
import com.hxzy.service.UmsMemberTagService;
import com.hxzy.service.impl.UmsMemberTagServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;
import java.math.BigDecimal;

@WebServlet("/UmsMemberTag/insert")
public class insert extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException {
        req.getRequestDispatcher("/WEB-INF/pmsbrand/insert.jsp").forward(req,res);
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException {
        req.setCharacterEncoding("UTF-8");
        res.setCharacterEncoding("UTF-8");
        res.setContentType("text/html;charset=UTF-8");

        UmsMemberTag tag=new UmsMemberTag();

        String name=req.getParameter("name");
        tag.setName(name);

        /**
         * 自动打标签完成订单数量
         */
        Integer finishOrderCount=Integer.parseInt(req.getParameter("finishOrderCount"));
        tag.setFinishOrderCount(finishOrderCount);

        /**
         * 自动打标签完成订单金额
         */
        BigDecimal finishOrderAmount=BigDecimal.valueOf(Double.parseDouble(req.getParameter("finishOrderAmount")));
        tag.setFinishOrderAmount(finishOrderAmount);

        UmsMemberTagService service=new UmsMemberTagServiceImpl();
        boolean insert = service.insert(tag);

        PrintWriter out=res.getWriter();
        out.println( insert? "新增成功": "新增失败");
        //输出刷新
        out.flush();
        out.close();
    }
}
